package dbu.dbase.version3;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import dbu.dbase.DBaseStructure;

public class MdxEntry extends DBaseStructure {

	/** Pointer to lower level */
	private int lower;

	/** Record number in data file */
	private int record;

	private double key;

	/**
	 * Read  
	 * @param stream
	 * @throws IOException
	 */
	@Override
	protected int read(InputStream stream) throws IOException {
		/** 4 byte */
		lower = readInt(stream);
		/** 4 byte */
		record = readInt(stream);
		/** 8 byte */
		key = readDouble(stream);

		return 16;
	}

	/**
	 * Write 
	 * @param stream
	 * @throws IOException
	 */
	protected void write(OutputStream stream) throws IOException {
		/** 4 byte */
		stream.write(lower);
		/** 4 byte */
		stream.write(record);
		/** 8 byte */
		writeDouble(stream, key);
	}

	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		result.append("lower:  "); result.append(lower); result.append("\n");
		result.append("record: "); result.append(record); result.append("\n");
		result.append("key:    "); result.append(key); result.append("\n");
		return result.toString();
	}

}
